﻿@page "/Manager/index.html"
@using Newbe.BookmarkManager.Services
@inherits Blazor.BrowserExtension.Pages.IndexPage

<Layout Class="site-layout-background" Style="min-height: 100vh">
    <Header>
        <PageHeader BackIcon="@false" Ghost="true" Style="width: 1200px;height: 64px;margin: 0 auto">
            <PageHeaderAvatar>
                <Avatar Src="/icons/32icon.png"/>
            </PageHeaderAvatar>
            <PageHeaderTitle>
                <Text Style="color: white">Amazing Favorites</Text>
            </PageHeaderTitle>
            <PageHeaderTags>
                <Tag PresetColor="@PresetColor.Blue">@Consts.CurrentVersion</Tag>
            </PageHeaderTags>
            <PageHeaderSubtitle></PageHeaderSubtitle>
            <PageHeaderExtra>
                <ManagerButton></ManagerButton>
            </PageHeaderExtra>
        </PageHeader>
    </Header>
    <Content Style="width: 1200px;margin: 20px auto">
        <Row>
            <Col Span="24">
                <AntList Bordered DataSource="@_targetBks">
                    <Header>
                        <Row Gutter="(16,24)">
                            <Col Span="24">
                                <Spin Spinning="@_searchInputLoading">
                                    <AutoComplete Options="@SearchOptions">
                                        <ChildContent>
                                            <AutoCompleteSearch EnterButton="true"
                                                                AutoFocus="true"
                                                                Placeholder="input keyword to search"
                                                                @ref="_search"
                                                                @bind-Value="SearchValue">
                                            </AutoCompleteSearch>
                                        </ChildContent>
                                    </AutoComplete>
                                </Spin>
                            </Col>
                            @if (_userOptions?.HotTagsFeature?.Enabled == true)
                            {
                                <antdesign.Col Span="10">
                                    <HotTags OnTagClick="e => OnClickTag(e.Tag.Tag)"/>
                                </antdesign.Col>
                            }
                        </Row>
                    </Header>
                    <ChildContent Context="bk">
                        <ListItem @key="@bk.Bk.Url">
                            <Col Span="24">
                                <Space>
                                    <SpaceItem>
                                        @if (bk.ShowIndex && bk.LineIndex < 10)
                                        {
                                            <code>alt + </code>
                                        }
                                        @bk.LineIndex
                                    </SpaceItem>
                                    <SpaceItem>
                                        <Button Type="link"
                                                OnClick="e => OnClickUrl(bk, e)">
                                            <Space>
                                                <SpaceItem>
                                                    @if (!string.IsNullOrEmpty(bk.Bk.FavIconUrl))
                                                    {
                                                        <Badge Count="bk.Bk.ClickedCount"
                                                               Size="small"
                                                               Style="background-color: #52c41a; ">
                                                            <ChildContent>
                                                                <Image Width="16px"
                                                                       Height="16px"
                                                                       Preview="false"
                                                                       Src="@bk.Bk.FavIconUrl"
                                                                       Fallback="@WebHelper.DefaultImagePlaceHolder"/>
                                                            </ChildContent>
                                                        </Badge>
                                                    }
                                                </SpaceItem>
                                                <SpaceItem>@bk.Bk.Title</SpaceItem>
                                            </Space>
                                        </Button>
                                    </SpaceItem>
                                    <SpaceItem>
                                        @if (bk.Bk.Tags != null)
                                        {
                                            @foreach (var tag in bk.Bk.Tags)
                                            {
                                                <Tag Closable="true"
                                                     @key="@tag"
                                                     OnClosing="e => OnRemovingTag(bk.Bk, tag)"
                                                     OnClick="e => OnClickTag(tag)"
                                                     Color="@WebHelper.GetTagColor(tag)">
                                                    @tag
                                                </Tag>
                                            }
                                        }
                                    </SpaceItem>
                                    <SpaceItem>
                                        <TagInput OnNewTagsCreated="e => OnNewTagsAddAsync(bk, e.Tags)"
                                                  Options="_allTags">
                                        </TagInput>
                                    </SpaceItem>
                                    <SpaceItem>
                                        <Button Shape="circle"
                                                Icon="edit"
                                                Size="small"
                                                OnClick="e => OnClickEdit(bk.Bk.Url, bk.Bk.Title)"/>
                                    </SpaceItem>
                                    <SpaceItem>
                                        <Button Shape="circle"
                                                Icon="share-alt"
                                                Size="small"
                                                OnClick="e => OnClickSharing(bk.Bk.Url)"/>
                                    </SpaceItem>
                                </Space>
                            </Col>
                        </ListItem>
                    </ChildContent>
                    <Footer>

                    </Footer>
                </AntList>
            </Col>
        </Row>
    </Content>
    <Footer Style="text-align: center;">
        <Space Direction="DirectionVHType.Vertical">
            <SpaceItem>
                <TipsAlert/>
            </SpaceItem>
            <SpaceItem>Welcome to submit you suggestion at <a href="https://github.com/newbe36524/Amazing-Favorites/issues" target="_blank">github.com</a></SpaceItem>
            <SpaceItem>
                <a href="@StaticUrlOptions.Value.PrivacyAgreement" target="_blank">Privacy Agreement</a>
            </SpaceItem>
        </Space>
    </Footer>
</Layout>


@{
    RenderFragment editFormFooter = @<Template>
                                        <Button OnClick="OnSharingButton">
                                            Sharing
                                        </Button>
                                        <Button OnClick="OnClickModalRemoveAsync"
                                                Type="danger">
                                            Remove
                                        </Button>
                                        <Button OnClick="OnClickModalSaveAsync"
                                                Type="primary">
                                            Save
                                        </Button>
                                        <Button OnClick="OnClickModalCancelAsync">
                                            Cancel
                                        </Button>
                                    </Template>;
}


<Modal Title="@("Edit Bookmark")"
       Visible="@_modalVisible"
       Width="1000"
       Footer="@editFormFooter">
    <Spin Tip="Loading..."
          Spinning="@_isFormLoading">
        <BkEditForm
            BkEditFormModel="@BkEditFormData">
        </BkEditForm>
    </Spin>
</Modal>

<AfCodePanel @bind-Visible="@_afCodeSharingPanelVisible"
             Url="@_afCodeSharingUrl">

</AfCodePanel>

<AfAddScript Src="content/manager_keyboard.js" Async="false" Defer="false"/>
@if (_userOptions is
{
    AcceptPrivacyAgreement: true,
    ApplicationInsightFeature:
    {
        Enabled: true
        }
    })
{
    <AfAddScript Src="content/ai.js" Async="false" Defer="false"/>
}